package com.intretech.umsin.oss.config;

import com.intretech.umsin.oss.util.MinioUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version V1.0
 * @ClassName: MinIOConfig
 * @Description: MinIOConfig 服务实现
 * @author: 李启联
 * @date: 2022-04-25 16:35
 * @Copyright: Copyright (c) 2022
 */
@Configuration
@ConfigurationProperties(ignoreUnknownFields = true, prefix = "minio.oss")
@ConditionalOnProperty(name = "oss-type",havingValue = "MINIO",matchIfMissing = false)
public class MinIOConfig {

    private String  endpoint;// MINIO服务所在地址
    private String  bucketName;//#存储桶名称
    private String  accessKey;// #访问KEY
    private String  secretKey;// #访问秘钥
    private Integer signedUrlExpires; //对象临时授权链接失效时间(单位为秒)

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public Integer getSignedUrlExpires() {
        return signedUrlExpires;
    }

    public void setSignedUrlExpires(Integer signedUrlExpires) {
        this.signedUrlExpires = signedUrlExpires;
    }

    @Bean
    public MinioUtil minioUtil() throws Exception {
        MinioUtil minioUtil = new MinioUtil(getEndpoint(),getBucketName(),getAccessKey(),getSecretKey(),getSignedUrlExpires());
        return minioUtil;
    }

}
